//
//  ViewController.m
//  liveTest
//
//  Created by bijan on 2016/12/20.
//  Copyright © 2016年 Zhu jinxin. All rights reserved.
//

#import "ViewController.h"
#import <IJKMediaFramework/IJKMediaFramework.h>

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIView *PlayView;
@property (nonatomic,strong) IJKFFMoviePlayerController *player;
@property (weak, nonatomic) IBOutlet UIButton *stopButton;

@end

@implementation ViewController{
    
    NSString *_url;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    [self.PlayView addSubview:self.player.view];


}

//rtmp://192.168.0.62:1234/liveTest/room
- (IJKFFMoviePlayerController *)player
{
    if (!_player)
    {
        IJKFFOptions *options = [IJKFFOptions optionsByDefault];
        _player = [[IJKFFMoviePlayerController alloc] initWithContentURLString:@"rtmp://192.168.0.62:1234/liveTest/room" withOptions:options];
        _player.view.frame = self.PlayView.bounds;
        _player.scalingMode = IJKMPMovieScalingModeAspectFill;
        [_player prepareToPlay];
    }
    return _player;
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    
    [_player pause];
    [_player stop];
    
}

- (IBAction)stopButtonClick:(UIButton *)sender {
    
    if (_player.playbackState == IJKMPMoviePlaybackStatePlaying) {
        [_stopButton setTitle:@"play" forState:UIControlStateNormal];
         [_player pause];
    }else{
         [_stopButton setTitle:@"pause" forState:UIControlStateNormal];
         [_player play];
    }
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];

    NSLog(@"memory warning");

}

- (void)dealloc{
    [_player pause];
    [_player stop];
}

@end
